import {request} from "umi";

/**
 * 以下为数字对象元数据管理模块的接口
 */

/** 通过doi得到DOMeta的详情
 * POST 参数doID
 * /doa/reg/metado/getDetailByID */

export async function getDetailByID(params, options) {
  const res = request('/doa/reg/metado/getDetailByID', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/** 获取DO列表
 * POST 参数userID
 * /doa/reg/metado/getByUser */

export async function getByUser(params, options) {
  const res = request('/doa/reg/metado/getByUser', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/** 获得所有DO
 * GET 无参数
 * /doa/reg/metado/getAllGroupByUser */
export async function getAllGroupByUser(params, options) {
  const res = request('/doa/reg/metado/getAllGroupByUser', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/** 返回访问次数最多的1前100个MetaDO的ID以及其Title
 * POST 参数size
 * /doa/reg/metado/getHottest */
export async function getHottest(params, options) {
  const res = request('/doa/reg/metado/getHottest', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/** 创建DO
 * POST 参数为Json格式的DO字符串，id不可为空
 * {
            "id": "86.5000.470/do.hello",
            "type": "0.TYPE/DO.Metadata",
            "attributes": {
                "metadata": {
                    "标题": "柳熠发推：什么时候由媒体来宣布下任总统了？",
                    "来源": "环球网",
                    "分类": "新闻"
                }
            }
        }
 *  /doa/reg/metado/create */

export async function create(params, options) {
  const res = request('/doa/reg/metado/create', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/** 删除DO
 * POST 参数为doID
 * /doa/reg/metado/delete */
export async function deleteDO(params, options) {
  const res = request('/doa/reg/metado/delete', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/** 返回100条搜索匹配的结果，每条结果包含所有元数据
 * GET 参数query
 * /doa/reg/metado/search */

export async function search(params, options) {
  const res = request('/doa/reg/metado/search', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/**
 * 返回统计信息
 */
export async function getStat(params, options) {
  const res = request('/doa/reg/metado/getStat', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}






/**
 * 以下为仓库管理模块的接口
 */

/**
 * 获取reg的信息
 * @param params
 * @param options
 * @returns {Promise<*>}
 */
export async function getRegInfo(params, options) {
  const res = request('/doa/reg/getRegInfo', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/**
 * 获取LRS的访问地址
 * @param params
 * @param options
 * @returns {Promise<URL>}
 */
export async function getLRSInfo(params, options) {
  const res = request('/doa/reg/getLRSInfo', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/**
 * 获取链接的reg的信息
 * @param params
 * @param options
 * @returns {Promise<*>}
 */
export async function getInRegs(params, options) {
  const res = request('/doa/reg/getInRegs', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/**
 * 获取接出的Registry信息
 * @param params
 * @param options
 * @returns {Promise<*>}
 */
export async function getOutRegs(params, options) {
  const res = request('/doa/reg/getOutRegs', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}

/**
 * 获取的reg的状态信息
 * @param serviceID
 * @param options
 * @returns {Promise<DoipServiceInfo>}
 */
export async function getDoipInfo(params, options) {
  const res = request('/doa/reg/getDOIPServiceInfo', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/**
 * 测试的reg的状态信息
 * @param serviceID
 * @param options
 * @returns {Promise<boolean>}
 */
export async function testRemoteRegConnection(params, options) {
  const res = request('/doa/reg/testRemoteReg', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}


/**
 * 连接reg
 * @param serviceID
 * @param options
 * @returns {Promise<boolean>}
 */
export async function connectRemoteReg(params, options) {
  const res = request('/doa/reg/connectRemoteReg', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    params: {...params},
    ...(options || {}),
  });
  return res
}






